#include "HerzeleidPrecompiled.hxx"
#include "HerzeleidCore.hxx"

#define HerzeleidMaxDebugNameLength (64)

#ifdef HERZELEID_DEBUG

void Herzeleid::DirectXNative::SetDebugName(
	_In_ ID3D11Device *pObj, 
	_In_ const wchar_t *pstrName 
	)
{
	char szNameString[HerzeleidMaxDebugNameLength];
    auto iNameStringLength = WideCharToMultiByte(
        CP_ACP, 0, pstrName, -1, szNameString, 
		HerzeleidMaxDebugNameLength,
        nullptr, 
		nullptr
        );

	if ( pObj )
	{
		pObj->SetPrivateData(
			WKPDID_D3DDebugObjectName,
			iNameStringLength - 1,
			szNameString
			);
	}
}

void Herzeleid::DirectXNative::SetDebugName( 
	_In_ ID3D11DeviceChild *pObj, 
	_In_ const wchar_t *pstrName 
	)
{
	char szNameString[HerzeleidMaxDebugNameLength];
    auto iNameStringLength = WideCharToMultiByte(
        CP_ACP, 0, pstrName, -1, szNameString, 
		HerzeleidMaxDebugNameLength,
        nullptr, 
		nullptr
        );

	if ( pObj )
	{
		pObj->SetPrivateData(
			WKPDID_D3DDebugObjectName,
			iNameStringLength - 1,
			szNameString
			);
	}
}

void Herzeleid::DirectXNative::SetDebugName( 
	_In_ IDXGIObject *pObj, 
	_In_ const wchar_t *pstrName 
	)
{
	char szNameString[HerzeleidMaxDebugNameLength];
    auto iNameStringLength = WideCharToMultiByte(
        CP_ACP, 0, pstrName, -1, szNameString, 
		HerzeleidMaxDebugNameLength,
        nullptr, 
		nullptr
        );

	if ( pObj )
	{
		pObj->SetPrivateData(
			WKPDID_D3DDebugObjectName,
			iNameStringLength - 1,
			szNameString
			);
	}
}

 #ifdef HERZELEID_DESKTOP

void Herzeleid::DirectXNative::SetDebugName(
	_In_ ID3D11Device *pObj, 
	_In_ const char *pstrName 
	)
{
	if ( pObj )
	{
		pObj->SetPrivateData( 
			WKPDID_D3DDebugObjectName, 
			lstrlenA(pstrName), 
			pstrName 
			);
	}
}

void Herzeleid::DirectXNative::SetDebugName( 
	_In_ ID3D11DeviceChild *pObj, 
	_In_ const char *pstrName 
	)
{
	if ( pObj )
	{
		pObj->SetPrivateData( 
			WKPDID_D3DDebugObjectName, 
			lstrlenA(pstrName), 
			pstrName 
			);
	}
}

void Herzeleid::DirectXNative::SetDebugName( 
	_In_ IDXGIObject *pObj, 
	_In_ const char *pstrName 
	)
{
	if ( pObj )
	{
		pObj->SetPrivateData( 
			WKPDID_D3DDebugObjectName, 
			lstrlenA(pstrName), 
			pstrName 
			);
	}
}

Herzeleid::Standard::Named::Named() : 
	m_wszName( L"Undefined" )
{
}

Herzeleid::Standard::Named::Named( String16ConstRef wszName ) : 
	m_wszName( wszName ) 
{ 
}

String16ConstPtrConst Herzeleid::Standard::Named::PropertyGetterForDebugName()
{
	return( &m_wszName );
}

String16ConstPtrConst Herzeleid::Standard::Named::PropertyGetterForDebugName() const
{
	return( &m_wszName );
}

Void Herzeleid::Standard::Named::PropertySetterForDebugName( String16ConstRef wszName )
{
	m_wszName = wszName;
}

 #else // !HERZELEID_DESKTOP

void Herzeleid::DirectXNative::SetDebugName(
	_In_ ID3D11Device *pObj, 
	_In_ const char *pstrName 
	)
{
	if ( pObj )
	{
		std::string szName(pstrName);
		pObj->SetPrivateData( 
			WKPDID_D3DDebugObjectName, 
			static_cast<DWord>(szName.size()), 
			pstrName 
			);
	}
}

void Herzeleid::DirectXNative::SetDebugName( 
	_In_ ID3D11DeviceChild *pObj, 
	_In_ const char *pstrName 
	)
{
	if ( pObj )
	{
		std::string szName(pstrName);
		pObj->SetPrivateData( 
			WKPDID_D3DDebugObjectName, 
			static_cast<DWord>(szName.size()), 
			pstrName 
			);
	}
}

void Herzeleid::DirectXNative::SetDebugName( 
	_In_ IDXGIObject *pObj, 
	_In_ const char *pstrName 
	)
{
	if ( pObj )
	{
		std::string szName(pstrName);
		pObj->SetPrivateData( 
			WKPDID_D3DDebugObjectName, 
			static_cast<DWord>(szName.size()), 
			pstrName 
			);
	}
}

Herzeleid::Standard::Named::Named() : 
	m_wszName( L"Undefined" )
{
}

Herzeleid::Standard::Named::Named( Platform::String^ wszName ) : 
	m_wszName( wszName ) 
{ 
}

Platform::String^ Herzeleid::Standard::Named::DebugName::get(
	)
{
	return( m_wszName );
}

Void Herzeleid::Standard::Named::DebugName::set( 
	Platform::String^ wszName
	)
{
	m_wszName = wszName;
}

 #endif // !HERZELEID_DESKTOP



#endif // !HERZELEID_DEBUG